package server;

import server.SQLDatabase;



public class ServerMain {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try{
			
		SQLDatabase jdb = new SQLDatabase();
		

		/** Connection Test */
		System.out.println("Connecting...");
		if (jdb.openConnection("db53", "01831861")) {
			System.out.println("Connected to d^_^b (database)");
		} else {
			System.out.println("Could not connect to database");
		}
		
//		String salt = jdb.getSalt("Doctor");
//		System.out.println(salt);
		
		String f = jdb.getJournal("DoctorPat", "Nurse");
		System.out.print(f);
		
//		if(jdb.modifyJournal(45, "Doctor", "Test-text")){
//			System.out.println("changes been made successfully!");
//		}else{
//			System.out.println("something is wrong!");
//		}
		
//		/**Try to Login */
//		if(jdb.tryLogin("Doctor", "pass")){
//			System.out.println("Doctor logged id");
//		}else{
//			System.out.println("Doctor error when logged id");
//		}
		
//		/** Save to log Test */
//		if (jdb.saveToLog("Dr Lundberg", "logged in")) {
//			jdb.saveToLog("Dr Lundberg", "logged off");
//			System.out.println("LoginSavedToLog SUCCESS!");
//		} else {
//			System.out.println("LoginSavedToLog FAIL!");
//		}
		
		
//		/** InsertClient Test */
//		if(jdb.insertClient(3, "DoctorPat", 2, "pass")){
//			System.out.println("insertClient SUCCESS!");
//		}else{
//			System.out.println("insertClient FAIL!");
//		}
		
		
//		/** InsertJournal Test */
//		if (jdb.insertJournal("Patient", "Nurse", "Doctor", 2, "v�rk", "Doctor")) {
//			System.out.println("InsertJournal SUCCESS!");
//		} else {
//			System.out.println("InsertJournal FAIL!");
//		}

		
//		/** 
//		 WORKING!!*/
//		 if(jdb.insertClient(0, "Government", 1, "pass") &&
//		 jdb.insertClient(1, "Doctor", 1, "pass")&&
//		 jdb.insertClient(2, "Nurse", 1, "pass")&&
//		 jdb.insertClient(3, "Patient", 1, "pass")){
//		 System.out.println("Correct inserted clients!");
//		 }else{
//		 System.out.println("Wrong inserted clients!");
//		 }

		
//		/** DeleteJournal Test */
//		if (jdb.deleteJournal("1", "Government")) {
//			System.out.println("DeleteJournal SUCCESS!");
//		} else {
//			System.out.println("DeleteJournal FAIL!");
//		}
		
		
		/** Checks if a client exists in the database */
//		if (jdb.clientExists("Doctor")) {
//			System.out.println("ClientExists SUCCESS!");
//		} else {
//			System.out.println("ClientExists FAIL!");
//		}

		
//		/** Checks if a client are returned from the database */
//		Client clip = jdb.getClient("Patient");
//		System.out.println("ID: " + clip.getID() + " Auth: " + clip.getAuthority()
//				+ " Div: " + clip.getDivision());
//		
//		Client clin = jdb.getClient("Nurse");
//		System.out.println("ID: " + clin.getID() + " Auth: " + clin.getAuthority()
//				+ " Div: " + clin.getDivision());
//		
//		Client clid = jdb.getClient("Doctor");
//		System.out.println("ID: " + clid.getID() + " Auth: " + clid.getAuthority()
//				+ " Div: " + clid.getDivision());
		
		
		/** DONE THIS FAR*/
		 /** Checks if a journal are returned from the database*/
		
//		jdb.insertClient(3, "emil", 2,
//				"123");
//		jdb.insertJournal("emil", "Nurse", "Doctor", 2, "sjuk", "Doctor");
		
//		 ArrayList<Journal> j = jdb.getJournal("emil", "Government");
//		 System.out.println(j.toString());
//		int i = 0;
//		 while(j.size() > i){
//		 System.out.println("Patient: " + j.get(i).getPatient() + " \nNurse: " + j.get(i).getNurse() + " \nDoctor: " + j.get(i).getDoctor() + " \nDivision: " + j.get(i).getDivision() + " \nData: " + j.get(i).getData());
//		System.out.println();
//		 i++;
//		 }
//		Journal j = jdb.getJournalObject(67, "Doctor");
//		 System.out.println("Patient: " + j.getPatient() + " \nNurse: " + j.getNurse() + " \nDoctor: " + j.getDoctor() + " \nDivision: " + j.getDivision() + " \nData: " + j.getData());

		
//		System.out.print(jdb.getJournal("emil", "Government"));
		// ArrayList<Journal> j = jdb.getJournal("1");
		// System.out.print(j.get(0));
		// System.out.print(j.get(1));
		// Journal j = jdb.getJournal("2", "Doctor");
		// System.out.print(j.toString());
		//
		// System.out.println(jdb.findJournal("199102072353"));
		} catch(Exception e){
			System.out.println("FEEEEL");
		}
		
	}
}
